<?PHP
$dbhost = "localhost";
$dbuser = "";
$dbpass = "";
$dbname = "mydns";

if (!($request = json_decode($HTTP_RAW_POST_DATA)))
	exit;

if (!($dbconn = mysql_connect($dbhost, $dbuser, $dbpass)))
	exit;
if (!(mysql_select_db($dbname)))
	exit;

$query = "SELECT distinct city FROM $dbname.geocity_locs
		WHERE cname = '" . strtoupper($request->cname) . "'
		AND city like '" . strtoupper($request->city) . "%'
		ORDER BY city ASC LIMIT 0,5";

$res = mysql_query($query);
if (!$res)
	exit;	

$aSuggestions = array();
while($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
	array_push($aSuggestions, $row['city']);
}
mysql_free_result($res);
mysql_close($dbconn);

header("Content-Type: text/plain; charset=UTF-8");
echo json_encode($aSuggestions);

/* vi:set ts=4: */?>
